<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
    
    <head>
        <meta charset="utf-8">
        <title>
            设计服务
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="/css/x-admin.css" media="all">
    </head>
    
    <body>
        <div class="x-body">
            <form class="layui-form">

                <div class="layui-form-item">
                    <label for="bigTitle" class="layui-form-label">
                        <span class="x-red">*</span>大标题
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" th:value="${shiGong.bigTitle}"  id="bigTitle" name="bigTitle" required="" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="title1" class="layui-form-label">
                        <span class="x-red">*</span>小标题1
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" th:value="${shiGong.title1}" id="title1" name="title1"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="title2" class="layui-form-label">
                        <span class="x-red">*</span>小标题2
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" th:value="${shiGong.title2}" id="title2" name="title2"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="link" class="layui-form-label">
                        <span class="x-red">*</span>图片
                    </label>
                    <div class="layui-input-inline">
                        <div class="site-demo-upbar">
                            <input type="file" name="upfile" class="layui-upload-file" id="test">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="link" class="layui-form-label">
                        <span class="x-red">*</span>图片预览
                    </label>
                    <div class="layui-input-inline" id="productImage">
                        <div class="site-demo-upbar">

                        </div>
                    </div>
                </div>


                <br><br>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label">
                    </label>
                    <button  class="layui-btn" lay-filter="add" lay-submit="">
                        保存
                    </button>
                </div>
            </form>


            <div class="x-body" id="bannerApp">
                <table class="layui-table">
                    <thead>
                    <tr>
                        <th>
                            图片
                        </th>

                        <th>
                            操作
                        </th>

                    </tr>
                    </thead>
                    <tbody id="productTable">

                    </tbody>
                </table>

                <div id="page"></div>
            </div>


        </div>
        <script src="/js/jquery-2.2.4.min.js" charset="utf-8">
        </script>
        <script src="/lib/layui/layui.js" charset="utf-8">
        </script>
        <script src="/js/x-layui.js" charset="utf-8">
        </script>
        <script src="/js/vue.js" charset="utf-8">
        </script>
        <script type="text/javascript" src="/js/wangEditor.js"></script>
        <script>

            $(document).ready(function () {
                loadHomePicture();
            });

            var imageFilename = '[[${shiGong.picName}]]';

            layui.use(['form','layer', 'upload'], function(){
                $ = layui.jquery;
              var form = layui.form();
              var layer = layui.layer;

                layui.upload({
                    url: '/bo/homePicture/upload.html', //上传接口
                    success: function(res){ //上传成功后的回调
                        imageFilename = res.data.filename;
                        $('#productImage').html('<img src="'+ res.data.imageUrl +'" width="100px" height="40px">');
                    }
                });

                var featurePro = [];
              //监听提交
              form.on('submit(add)', function(data){


                //发异步，把数据提交给服务器
                  $.ajax({
                      url: '/bo/saveshejishi.html',
                      type: 'POST', //GET
                      async: true,    //或false,是否异步
                      data: {
                          bigTitle : $('#bigTitle').val(),
                          title1 : $('#title1').val(),
                          title2 : $('#title2').val(),
                          picUrl : imageFilename,
                          valueType : 10
                      },
                      timeout: 10000,    //超时时间
                      dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                      success: function (ajaxData, textStatus, jqXHR) {
                          if (1000 != ajaxData.code) {
                              layer.alert(ajaxData.message, {icon: 6},function () {});
                              return;
                          }

                          $('#productImage').html('<img src="" width="100px" height="40px">');
                          loadHomePicture();

                      }
                  });

                return false;
              });
            });

            function loadHomePicture() {
                $.ajax({
                    url: '/bo/shejishilist.html',
                    type: 'GET', //GET
                    async: true,    //或false,是否异步
                    data: {
                        valueType : 10
                    },
                    timeout: 10000,    //超时时间
                    dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                    success: function (ajaxData, textStatus, jqXHR) {
                        if (1000 != ajaxData.code) {
                            layer.alert(ajaxData.message, {icon: 6},function () {});
                            return;
                        }

                        let msg = '';
                        let results = ajaxData.data;
                        for (let i=0;i<results.length;i++) {
                            msg += '                            <tr>\n' +
                                '                                <td><img src="'+results[i].picUrl+'" width="60px" height="40px"></td>\n' +
                                '                                <td><button onclick="del('+results[i].id+')">删除</button></td>\n' +
                                '                            </tr>';
                        }
                        $('#productTable').html(msg);
                    }
                });
            }

            function del(id) {
                $.ajax({
                    url: '/bo/deleteKeyValue.html',
                    type: 'POST', //GET
                    async: true,    //或false,是否异步
                    data: {
                        id : id
                    },
                    timeout: 10000,    //超时时间
                    dataType: 'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                    success: function (ajaxData, textStatus, jqXHR) {
                        if (1000 != ajaxData.code) {
                            layer.alert(ajaxData.message, {icon: 6},function () {});
                            return;
                        }

                        loadHomePicture();
                    }
                });
            }

        </script>
        <script>

        </script>
    </body>

</html>